import React from 'react'
import { Table,Input,Button} from 'antd';
import axios from '../service.js'
class Account extends React.Component {
      constructor(props){
        super(props);
        this.state = { branch:"",alldata:[]};
        this.columns = [
          {
            title: '机构',
            dataIndex: 'branch',
            key: 'branch',
          },
          {
            title: '区域',
            dataIndex: 'region',
            key: 'region',
          },
          {
            title: '录入状态',
            dataIndex: 'commonflag',
            key: 'commonflag',
            filters: [
              {
                text: '暂未录入',
                value: 0,
              },
              {
                text: '录入成功',
                value: 1,
              },{
                text: '录入失败',
                value: 2,
              },{
                text: '暂无账号',
                value: 3,
              },{
                text: '登陆不上',
                value: 4,
              },{
                text: '异常',
                value: 5,
              }
            ],
            
            render: (val) => {
              let state=""
              switch(val){
                   case 0 :
                     state="暂未录入";
                     break;
                   case 1:
                     state="录入成功";
                     break;
                   case 2:
                     state="录入失败";
                     break;
                   case 3:
                     state="暂无账号";
                     break;
                   case 4:
                     state="登陆不上";
                     break;
                   case 5:
                     state="异常";
                     break;
                    default:
                      state="暂未处理"

              }
              return state;
       }
          },
          {
            title: '审核状态',
            dataIndex: 'auditflag',
            key: 'auditflag',
            filters: [
              {
                text: '暂未审核',
                value: 0,
              },
              {
                text: '审核成功',
                value: 1,
              },{
                text: '审核失败',
                value: 2,
              },{
                text: '暂无账号',
                value: 3,
              },{
                text: '登陆不上',
                value: 4,
              },{
                text: '异常',
                value: 5,
              }
            ],
            render: (val) => {
                   let state=""
                   switch(val){
                        case 0 :
                          state="暂未审核";
                          break;
                        case 1:
                          state="审核成功";
                          break;
                        case 2:
                          state="审核失败";
                          break;
                        case 3:
                          state="暂无账号";
                          break;
                        case 4:
                          state="登陆不上";
                          break;
                        case 5:
                          state="异常";
                          break;
                        default:
                           state="暂未处理"
                          

                   }
                   return state;
            }
          }];
          
      }
      componentDidMount(){
        this.init();
      }
      handleTableChange = (pagination, filters, sorter) => {
          console.log(filters)
          let _this=this;
          _this.setState({alldata:[]});
          axios.post('/query/state',{branch:_this.state.branch,filters:JSON.stringify(filters)}).then((response)=>{
            let data=response.data;
            let dataArr=[];
            for(let i in data){
                 dataArr.push({
                     key:i,
                     branch:data[i]['branch'],
                     region:data[i]['region'],
                     commonflag:data[i]['commonflag'],
                     auditflag:data[i]['auditflag']
                 })
                 
            }
            //console.log(dataArr);
            _this.setState({alldata:dataArr});
          })
      }
      init=()=>{
           let _this=this;
           axios.post('/query/state',{branch:_this.state.branch,filters:JSON.stringify({commonflag:null,auditflag:null})}).then((response)=>{
               let data=response.data;
               let dataArr=[];
               for(let i in data){
                    dataArr.push({
                        key:i,
                        branch:data[i]['branch'],
                        region:data[i]['region'],
                        commonflag:data[i]['commonflag'],
                        auditflag:data[i]['auditflag']
                    })
                    
               }
               //console.log(dataArr);
               _this.setState({alldata:dataArr});
               //console.log(this.state.alldata)
           })
           
      }
      query=()=>{
          this.init();
      }
      changevalue=(e)=>{
          let bra=e.target.value;
          this.setState({branch:bra});
      }
      render(){
        return (
           <div>
             <div style={{float:"right"}}>
                <Input id="queryinput" autoComplete="off" allowClear={true}  placeholder="请输入机构名称" onChange={event => this.changevalue(event)} onPressEnter={this.query}  style={{width:"200px",marginRight:"10px"}}/>
                <Button  onClick={this.query}>查询</Button>
              </div>
              <Table onChange={this.handleTableChange} style={{paddingTop:50}} columns={this.columns} dataSource={this.state.alldata} />

              
           </div>
        )
      }
}
export default Account;